﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.IO;
using Ascentium.Utils;
using Ascentium.Utils.CrmScriptExport;

namespace Ascentium.Utils
{
	class Program
	{

		public static void Main(string[] args)
		{
		
			bool handled = true;
			
			string path = AppDomain.CurrentDomain.BaseDirectory;
			string search = "*.js";
			string operation = "*.js";
			string projectName = String.Empty;
			//string[] arglist = args[0].Split(new char[]{'/'});
			foreach (string arg in args)
			{
				if (arg.StartsWith("/O="))
				{
					operation = arg.Remove(0, 3);
				}
				if (arg.StartsWith("/P="))
				{
					path = arg.Remove(0, 3);
				}
				if (arg.StartsWith("/N="))
				{
					projectName = arg.Remove(0, 3);
				}
				else if (arg.StartsWith("/F="))
				{
					search = arg.Remove(0, 3);
				}
			}
            ScriptUploader uploader = new ScriptUploader(ScriptUploader.GetService());
            //Microsoft.Crm.SdkTypeProxy.WhoAmIRequest req = new Microsoft.Crm.SdkTypeProxy.WhoAmIRequest();
            //uploader.Service.Execute(req);

            ////uploader.GetCustomization(@"C:\Promise_AMO\MAIN\Ascentium.Crm.Promise.Customizations\Entities\Account.xml");
            //uploader.AppendToCustomizations(@"C:\Promise_AMO\MAIN\Ascentium.Crm.Promise.Customizations\Entities\Account.xml");
            ////uploader.AppendToCustomizations(@"C:\Promise_AMO\MAIN\Ascentium.Crm.Promise.Customizations\Entities\CA_grant.xml");
            ////uploader.AppendToCustomizations(@"C:\Promise_AMO\MAIN\Ascentium.Crm.Promise.Customizations\Extentions\ISV.Config.xml");
            ////uploader.AppendToCustomizations(@"C:\Promise_AMO\MAIN\Ascentium.Crm.Promise.Customizations\Extentions\sitemap.xml");
			
            //uploader.PushCustomizations(false);
            //return;
			switch (operation)
			{
				case "EXPORT":
					Console.WriteLine("Export Started");
					uploader.ExportAllCustomizationXML(path, projectName + ".csproj");
					Console.WriteLine("Export Completed");
					break;
				case "IMPORT":
					Console.WriteLine("Import Started");
					uploader.ImportAllCustomizationXML(path);
					Console.WriteLine("Import Completed");
					break;

			}
			
		}

		
	}
}
